package com.airlines.common;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;

/**
 * @author xxxx
 * @date 2017年12月4日
 * @description 将字符串按照分隔符转换成List或者Set
 */
public class StringToListUtil {
	
	public static List<String> getListDefault(String strs) {
		return getList(strs,",");
	}
	
	public static List<String> getList(String strs, String split) {
		List<String> list = new ArrayList<>();
		String[] strArray = null;
		if (StringUtils.isNotBlank(strs)) {
			strArray = strs.split(split);
			
			for (String s : strArray) {
				list.add(s);
			}
		}
		

		return list;
	}
	
	public static Set<String> getSet(String strs, String split) {
		List<String> list = getList(strs,split);
		Set<String>  set = new HashSet<>();
		set.addAll(list);
		return set;
	
	}
	
	public static String getString(List<String> list){
		StringBuffer sb = new StringBuffer();
		for(String s : list){
			sb.append(s);
			sb.append(",");
		}
		
		sb.deleteCharAt(sb.length()-1);
		return sb.toString();
	}
	
}
